<%-- 
    Document   : saveStop
    Created on : Jul 28, 2009, 4:20:13 PM
    Author     : david
--%>

<%@page contentType="text/html" pageEncoding="UTF-8" import="com.appspot.nnaplanner.DAL.*, com.appspot.nnaplanner.*"%>
<%
        if (request.getUserPrincipal() == null)
            response.sendError(response.SC_UNAUTHORIZED);
 

        if (request.getMethod().equals("POST")) {
            DALStop s = new DALStop(request.getParameter("id"),
                    request.getParameter("name"),
                    request.getParameter("description"));
            s.setConnected(request.getParameter("connected") != null);
            s.setLatitude(Float.parseFloat(request.getParameter("latitude")));
            s.setLongitude(Float.parseFloat(request.getParameter("longitude")));
            s.setKeywords(Utils.getKeywords(s.getName()));
            s.getKeywords().add(s.getID());
            s.save();
            NNappData.getGraph().addVertex(s.getID());
            Utils.generateConnections(s);
            DALGraph dg = new DALGraph();
            dg.save(NNappData.getGraph());
            out.print("{\"success\": \"true\"}");
        } else {
            out.print("{\"success\": \"false\", \"msg\":\"no data, method " + request.getMethod() + " \"}");
        }
%>